package com.xsmart.goods.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 *
 * @author Administrator
 * @date 2017/12/11
 */
@Component
public interface GoodsManageDao {
    /**
     * 查询所有商品
     * @param page
     * @param param
     * @return
     */
    @Select("<script>" +
            "SELECT t.goods_id, t.parent_goods_id,t.cat_id,t.user_id,t.promote_price,t.shop_price, " +
            "(select user_name from INFS_ADMIN_USER where user_id = t.user_id) user_name," +
            "t.goods_sn,t.goods_name,t.click_count,t.brand_id," +
            "t.goods_number,t.goods_weight,t.market_price,t.cost_price,t.supply_price," +
            "DATE_FORMAT(t.promote_start_date,'%Y-%m-%d %T')promote_start_date," +
            "DATE_FORMAT(t.promote_end_date,'%Y-%m-%d %T')promote_end_date," +
            "t.warn_number,t.keywords,t.goods_brief,t.goods_desc,t.goods_thumb,t.goods_img,t.is_real," +
            "(CASE WHEN t.is_on_sale = '0' THEN '下架' WHEN t.is_on_sale = '1' THEN '上架' WHEN t.is_on_sale = '2' THEN ' 挂起' END) is_on_sale, " +
            "t.is_alone_sale,t.add_time,t.sort_order,t.is_delete,t.is_best,t.is_new,t.is_hot,t.is_promote,t.goods_type,t.seller_note," +
            "t.give_integral,t.rank_integral,t.is_xiangou,t.mod_count, " +
            "DATE_FORMAT(t.xiangou_start_date,'%Y-%m-%d %T')xiangou_start_date," +
            "DATE_FORMAT(t.xiangou_end_date,'%Y-%m-%d %T')xiangou_end_date," +
            "t.xiangou_num,t.goods_tag,t.measure_unit,t.from_seller_id," +
            "(SELECT shop_name from seller_shopinfo where id = t.from_seller_id) from_seller_name," +
//          "<![CDATA[(case when t.is_promote=1 and NOW() BETWEEN t.promote_start_date AND t.promote_end_date then t.promote_price else t.shop_price end)]]> goods_price," +
            "<choose> " +
            "<when test=\"sellerId!=-1 and sellerId!=null and sellerId!=''\">(select shop_price from user_seller_goods u where u.goods_id = t.goods_id and u.id = #{sellerId}) goods_price,</when>" +
            "<when test='sellerId==-1'>t.shop_price goods_price,</when>" +
            "</choose>" +
            "b.brand_name,c.cat_name,g.cat_name typeName ,DATE_FORMAT(t.add_time,'%Y-%m-%d %T') add_times," +
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og WHERE og.goods_id = t.goods_id and exists(select * from order_info oi where oi.order_id = og.order_id and oi.order_status=1)),0) AS CHAR) good_sales," +
            "(SELECT iu.user_type FROM INFS_USER iu WHERE iu.user_id=#{userId}) user_type," +
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og WHERE og.goods_id = t.goods_id and exists(select * from order_info oi where oi.order_id = og.order_id and oi.order_status=1" +
            " and exists(select * from infu_distributor_member dm where dm.user_id = oi.user_id and dm.d_user_id =#{userId}))),0) AS CHAR) dis_sales" +
            " FROM goods t " +
            " LEFT JOIN brand b on t.brand_id =b.brand_id " +
            " LEFT JOIN category c on c.cat_id=t.cat_id " +
            " LEFT JOIN goods_type g on t.goods_type=g.cat_id " +
            "<where> " +
            "t.is_delete = 0 " +
            "<if test=\"goods_id!=null and goods_id!=''\"> and t.goods_id=#{goods_id}</if>" +
            "<if test=\"wx ==1 \"> and t.is_on_sale !=0 </if>"+
            "<if test=\"goods_sn!=null and goods_sn!=''\"> and t.goods_sn=#{goods_sn}</if>" +
            "<if test=\"goods_name!=null and goods_name!=''\"> and t.goods_name=#{goods_name}</if>" +
            "<if test=\"cat_id!=null and cat_id!=''\"> and t.cat_path_id like concat('%',#{cat_path_id},'%')</if>" +
            "<if test=\"brand_id!=null and brand_id!=''\"> and t.brand_id=#{brand_id}</if>" +
            "<if test=\"sellerId!=-1 and sellerId!=null and sellerId!= '' \"> and t.goods_id in (select goods_id  from user_seller_goods u where u.id =#{sellerId})</if> " +
            "</where>" +
            "</script>")
    List<Map<String,Object>> queryGoods(Pagination page, Map<String,Object> param);

    /**
     * 查询搜索结果
     * @param map
     * @return
     */
    @Select("<script>" +
            "select t.goods_id,t.goods_name,t.goods_img,t.goods_weight*1000 as goods_weight," +
            "(case when #{sellerId} = -1  then t.shop_price else t1.shop_price end) as  goods_price,"+
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og WHERE og.goods_id = t.goods_id and exists(select * from order_info oi where oi.order_id = og.order_id and oi.order_status=1)),0) AS CHAR) good_sales," +
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og WHERE og.goods_id = t.goods_id and exists(select * from order_info oi where oi.order_id = og.order_id and oi.order_status=1" +
            " and exists(select * from infu_distributor_member dm where dm.user_id = oi.user_id and dm.d_user_id =#{userId}))),0) AS CHAR) dis_sales " +
            "from goods t " +
            "LEFT JOIN user_seller_goods t1 on t1.goods_id = t.goods_id  " +
            "LEFT JOIN seller_shopinfo t2 on t2.id = t1.id  " +
            "LEFT JOIN infu_distributor_member t3 on t3.d_user_id = t2.ru_id " +
            "where  t.goods_name like concat('%',#{searchValue},'%') " +
            "<if test=\"sellerId!=-1 and sellerId!=null and sellerId!= '' \"> and t3.user_id = #{userId}</if>" +
            "</script>")
    List<Map<String,Object>> querySearchList(Pagination page, Map<String,Object> map);

    @Delete("DELETE FROM search_his WHERE user_id = #{userId} AND search_content = #{searchValue}")
    int deleteHisMap(Map<String, Object> deleteHisMap);

    /**
     * 新增搜索历史
     * @param searchHistoryMap
     * @return
     */
    @Insert("INSERT into search_his (user_id, search_content, search_time) VALUES (#{userId}, #{searchValue}, #{search_time})")
    int addSearchHistroy(Map<String, Object> searchHistoryMap);

    /**
     * 查询历史搜索记录
     * @param userId
     * @return
     */
    @Select("SELECT search_content, search_time from search_his WHERE user_id = #{userId} ORDER BY search_time DESC")
    List<String> querySearchHis(Integer userId);

    /**
     * 查询商品
     * @param goodsId
     * @param userId
     * @return
     */
    @Select("<script>" +
            "SELECT t.goods_id, t.parent_goods_id,t.cat_id,t.user_id,t.goods_sn,t.goods_name,t.click_count,t.brand_id," +
            "t.goods_number,t.goods_weight,t.market_price,t.cost_price,t.supply_price,t.shop_price,t.promote_price," +
            "DATE_FORMAT(t.promote_start_date,'%Y-%m-%d %T')promote_start_date," +
            "DATE_FORMAT(t.promote_end_date,'%Y-%m-%d %T')promote_end_date," +
            "t.warn_number,t.keywords,t.goods_brief,t.goods_desc,t.goods_thumb,t.goods_img,t.is_real,t.is_on_sale*1 as is_on_sale," +
            "t.is_alone_sale,t.add_time,t.sort_order,t.is_delete,t.is_best,t.is_new,t.is_hot,t.is_promote,t.goods_type,t.seller_note," +
            "t.give_integral,t.rank_integral,t.is_xiangou,t.mod_count, " +
            "DATE_FORMAT(t.xiangou_start_date,'%Y-%m-%d %T')xiangou_start_date," +
            "DATE_FORMAT(t.xiangou_end_date,'%Y-%m-%d %T')xiangou_end_date," +
            "t.xiangou_num,t.goods_tag,t.measure_unit,t.from_seller_id, " +
            "<![CDATA[(case when t.is_promote=1 and t.promote_start_date<=NOW() and t.promote_end_date>=NOW() then 1 else 0 end)]]> pricetype," +
            "CAST(IFNULL((select sum(og.goods_number) from order_goods og where og.goods_id=#{goodsId} and exists(select * from order_info oi where oi.order_id=og.order_id and oi.order_status=1)),0) AS CHAR) as salenum, " +
            "(select iu.user_type from INFS_USER iu where iu.user_id=#{userId}) as user_type, " +
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og " +
            "WHERE goods_id =#{goodsId} AND exists(SELECT *FROM order_info oi WHERE oi.order_id = og.order_id AND oi.order_status = 1 " +
            "AND exists(SELECT *FROM infu_distributor_member dm WHERE dm.user_id = oi.user_id AND dm.d_user_id =#{userId}))),0) AS CHAR) as d_salenum, " +
            "b.brand_name,c.cat_name,g.cat_name typeName ,DATE_FORMAT(t.add_time,'%Y-%m-%d %T') add_times " +
            " FROM goods t " +
            " LEFT JOIN brand b on t.brand_id =b.brand_id " +
            " LEFT JOIN category c on c.cat_id=t.cat_id " +
            " LEFT JOIN goods_type g on t.goods_type=g.cat_id " +
            "<where>" +
            " t.goods_id=#{goodsId}" +
            "</where>" +
            "</script>")
    Map<String,Object> queryGoodsInfo(@Param("goodsId")Integer goodsId,@Param("userId")Integer userId);

    /**
     * 查询商品购买次数
     * @param goodsId 商品id
     * @return 购买次数
     */
    @Select("select sum(goods_number) from order_goods where goods_id=#{goodsId}")
    int queryGoodsSellNumber(@Param("goodsId") Integer goodsId);

    /**
     * 查询商品的下一个主键值
     * @return
     */
    @Select("SELECT max(goods_id) FROM goods" )
    Integer queryMaxId();

    /**
     * 新增商品
     * @param goodsMap
     * @return
     */
    @Insert("INSERT INTO goods" +
            "(goods_id,parent_goods_id,cat_id,user_id,goods_sn,goods_name,click_count,brand_id,goods_number,goods_weight," +
            "market_price,cost_price,supply_price,shop_price,promote_price,promote_start_date,promote_end_date," +
            "warn_number,keywords,goods_brief,goods_desc,goods_thumb,goods_img,is_real,is_on_sale,is_alone_sale," +
            "add_time,sort_order,is_delete,is_best,is_new,is_hot,is_promote,goods_type,seller_note,give_integral," +
            "rank_integral,is_xiangou,xiangou_start_date,xiangou_end_date,xiangou_num,goods_tag,measure_unit," +
            "from_seller_id,mod_count, cat_path_id )" +
            "VALUES" +
            "(#{goodsMap.goods_id}, " +
            "#{goodsMap.parent_goods_id}," +
            "#{goodsMap.cat_id}," +
            "#{goodsMap.user_id}," +
            "#{goodsMap.goods_sn}," +
            "#{goodsMap.goods_name}," +
            "#{goodsMap.click_count}," +
            "#{goodsMap.brand_id}," +
            "#{goodsMap.goods_number}," +
            "#{goodsMap.goods_weight}," +
            "#{goodsMap.market_price}," +
            "#{goodsMap.cost_price}," +
            "#{goodsMap.supply_price}," +
            "#{goodsMap.shop_price}," +
            "#{goodsMap.promote_price}," +
            "#{goodsMap.promote_start_date}," +
            "#{goodsMap.promote_end_date}," +
            "#{goodsMap.warn_number}," +
            "#{goodsMap.keywords}," +
            "#{goodsMap.goods_brief}," +
            "#{goodsMap.goods_desc}," +
            "#{goodsMap.goods_thumb}," +
            "#{goodsMap.goods_img}," +
            "#{goodsMap.is_real}," +
            "#{goodsMap.is_on_sale}," +
            "#{goodsMap.is_alone_sale}," +
            "now()," +
            "#{goodsMap.sort_order}," +
            "#{goodsMap.is_delete}," +
            "#{goodsMap.is_best}," +
            "#{goodsMap.is_new}," +
            "#{goodsMap.is_hot}," +
            "#{goodsMap.is_promote}," +
            "#{goodsMap.goods_type}," +
            "#{goodsMap.seller_note}," +
            "#{goodsMap.give_integral}," +
            "#{goodsMap.rank_integral}," +
            "#{goodsMap.is_xiangou}," +
            "#{goodsMap.xiangou_start_date}," +
            "#{goodsMap.xiangou_end_date}," +
            "#{goodsMap.xiangou_num}," +
            "#{goodsMap.goods_tag}," +
            "#{goodsMap.measure_unit}," +
            "#{goodsMap.from_seller_id}," +
            "0," +
            "#{goodsMap.cat_path_id})")
    int addGoods(@Param("goodsMap") Map<String, Object> goodsMap);

    /**
     * 新增商品相册
     * @param goodsPhotoList
     * @param goods_id
     * @return
     */
    @Insert("<script>" +
            "insert into goods_photo " +
            "(goods_id, " +
            "goods_photo )" +
            "values " +
            "<foreach collection=\"goodsPhotoList\" item=\"item\" index=\"index\" separator=\",\" > " +
            "   (#{goods_id},#{item})" +
            "</foreach>" +
            "</script>")
    int addGoodsPhoto(@Param("goodsPhotoList")List goodsPhotoList,@Param("goods_id")Integer goods_id);


    /**
     * 更细商品信息
     * @param goodsMap
     * @return
     */
    @Insert("update goods " +
            "set " +
            "parent_goods_id = #{goodsMap.parent_goods_id}, " +
            "cat_id = #{goodsMap.cat_id}," +
            "user_id = #{goodsMap.user_id}," +
            "goods_sn = #{goodsMap.goods_sn}," +
            "goods_name = #{goodsMap.goods_name}," +
            "click_count = #{goodsMap.click_count}," +
            "brand_id = #{goodsMap.brand_id}," +
            "goods_number = #{goodsMap.goods_number}," +
            "goods_weight = #{goodsMap.goods_weight}," +
            "market_price = #{goodsMap.market_price}," +
            "cost_price = #{goodsMap.cost_price}," +
            "supply_price = #{goodsMap.supply_price}," +
            "shop_price = #{goodsMap.shop_price}," +
            "promote_price = #{goodsMap.promote_price}," +
            "promote_start_date = #{goodsMap.promote_start_date}," +
            "promote_end_date = #{goodsMap.promote_end_date}," +
            "warn_number = #{goodsMap.warn_number}," +
            "keywords = #{goodsMap.keywords}," +
            "goods_brief = #{goodsMap.goods_brief}," +
            "goods_desc = #{goodsMap.goods_desc}," +
            "goods_thumb = #{goodsMap.goods_thumb}," +
            "goods_img = #{goodsMap.goods_img}," +
            "is_real = #{goodsMap.is_real}," +
            "is_on_sale = #{goodsMap.is_on_sale}," +
            "is_alone_sale = #{goodsMap.is_alone_sale}," +
            "sort_order = #{goodsMap.sort_order}," +
            "is_delete = #{goodsMap.is_delete}," +
            "is_best = #{goodsMap.is_best}," +
            "is_new = #{goodsMap.is_new}," +
            "is_hot = #{goodsMap.is_hot}," +
            "is_promote = #{goodsMap.is_promote}," +
            "goods_type = #{goodsMap.goods_type}," +
            "seller_note = #{goodsMap.seller_note}," +
            "give_integral = #{goodsMap.give_integral}," +
            "rank_integral = #{goodsMap.rank_integral}," +
            "is_xiangou = #{goodsMap.is_xiangou}," +
            "xiangou_start_date = #{goodsMap.xiangou_start_date}," +
            "xiangou_end_date = #{goodsMap.xiangou_end_date}," +
            "xiangou_num = #{goodsMap.xiangou_num}," +
            "goods_tag = #{goodsMap.goods_tag}," +
            "measure_unit = #{goodsMap.measure_unit}," +
            "from_seller_id = #{goodsMap.from_seller_id}," +
            "mod_count = #{goodsMap.mod_count}  " +
            "where goods_id = #{goodsMap.goods_id}")
    int modGoods(@Param("goodsMap") Map goodsMap);

    /**
     * 转移商品至历史表
     * @param goods_id
     * @return
     */
    @Insert("INSERT INTO goods_his (goods_id,parent_goods_id,cat_id,user_id,goods_sn,goods_name,click_count,brand_id,goods_number," +
            "goods_weight,market_price,cost_price,supply_price,shop_price,promote_price,promote_start_date,promote_end_date," +
            "warn_number,keywords,goods_brief,goods_desc,goods_thumb,goods_img,is_real,is_on_sale,is_alone_sale,add_time,sort_order," +
            "is_delete,is_best,is_new,is_hot,is_promote,goods_type,seller_note,give_integral,rank_integral,is_xiangou,xiangou_start_date," +
            "xiangou_end_date,xiangou_num,goods_tag,measure_unit,from_seller_id ) " +
            "SELECT goods_id,parent_goods_id,cat_id,user_id,goods_sn,goods_name,click_count,brand_id,goods_number," +
            "goods_weight,market_price,cost_price,supply_price,shop_price,promote_price,promote_start_date,promote_end_date," +
            "warn_number,keywords,goods_brief,goods_desc,goods_thumb,goods_img,is_real,is_on_sale,is_alone_sale,add_time,sort_order," +
            "is_delete,is_best,is_new,is_hot,is_promote,goods_type,seller_note,give_integral,rank_integral,is_xiangou,xiangou_start_date," +
            "xiangou_end_date,xiangou_num,goods_tag,measure_unit,from_seller_id " +
            "FROM goods WHERE goods_id = #{goods_id}")
    int addGoodsHis(@Param("goods_id") Integer goods_id);

    /**
     * 修改商品状态
     * @param paramMap
     * @return
     */
    @Insert("update goods " +
            "set " +
            "is_on_sale = #{paramMap.isOnSale} " +
            "where goods_id = #{paramMap.goodsId}")
    int changeOnsale(@Param("paramMap")Map paramMap);

    /**
     *
     * 删除商品
     * @param goods_id
     * @return
     */
    @Delete("UPDATE goods " +
            "set " +
            "is_delete = 1  WHERE goods_id=#{goods_id}")
    int delGoods(Integer goods_id);

    /**
     * 商品唯一货号验证
     * @param goods_sn
     * @return
     */
    @Select("select goods_id from goods where goods_sn = #{goods_sn}")
    List<Map<String,Object>> checkGoodsSn(@Param("goods_sn") String goods_sn);

    /**
     * 查询商家信息
     * @return
     */
    @Select("select id as value, shop_name as label from seller_shopinfo where shop_type != 1")
    List<Map<String,Object>> querySellerShop();

    /**
     * 查询相册信息
     * @param goods_id
     * @return
     */
    @Select("select photo_id as uid, goods_photo as name from goods_photo where goods_id = #{goods_id} ")
    List<Map<String,Object>> queryGoodsPhoto(Integer goods_id);

    /**
     * 删除相册信息
     * @param goods_id
     * @return
     */
    @Delete("DELETE FROM goods_photo WHERE goods_id=#{goods_id}")
    int delGoodsPhoto(Integer goods_id);




    /**
     * 查询评价
     * @param page
     * @param goodsId
     * @return
     */
    @Select("SELECT t.goods_id,t.oga_text,iu.user_name,t.oga_service,t.oga_goods,t.oga_shipping,iu.user_picture," +
            "(select count(oga_goods) from order_goods_appraise t LEFT JOIN goods g  on t.goods_id = g.goods_id  where t.goods_id =#{goodsId}) as allComments," +
            "(select count(oga_goods) from order_goods_appraise t LEFT JOIN goods g  on t.goods_id = g.goods_id  where t.goods_id =#{goodsId} and oga_goods>3) as goodComments," +
            "(select count(oga_goods) from order_goods_appraise t LEFT JOIN goods g  on t.goods_id = g.goods_id  where t.goods_id =#{goodsId} and oga_goods=3) as midComments," +
            "(select count(oga_goods) from order_goods_appraise t LEFT JOIN goods g  on t.goods_id = g.goods_id  where t.goods_id =#{goodsId} and oga_goods<3) as nativeComments " +
            "FROM order_goods_appraise t " +
            "LEFT JOIN goods g on t.goods_id = g.goods_id " +
            "LEFT JOIN infs_user iu on t.user_id = iu.user_id " +
            "where t.goods_id = #{goodsId}")
    List<Map<String,Object>> queryGoodsSingle(Pagination page,@Param("goodsId")Integer goodsId);


    /**
     *
     * 查询好评
     * @param page
     * @param goodsId
     * @param ogaGoods
     * @return
     */
    @Select("SELECT t.goods_id,t.oga_text,iu.user_name,t.oga_service,t.oga_goods,t.oga_shipping,iu.user_picture  " +
            "FROM order_goods_appraise t " +
            "LEFT JOIN goods g on t.goods_id = g.goods_id " +
            "LEFT JOIN infs_user iu on t.user_id = iu.user_id " +
            "where " +
            " t.goods_id = #{goodsId} " +
            " and t.oga_goods > #{ogaGoods} ")
    List<Map<String,Object>> queryGoodComments(Pagination page,@Param("goodsId")Integer goodsId,@Param("ogaGoods")Integer ogaGoods);


    /**
     *
     * 查询差评
     * @param page
     * @param goodsId
     * @param ogaGoods
     * @return
     */
    @Select("SELECT t.goods_id,t.oga_text,iu.user_name,t.oga_service,t.oga_goods,t.oga_shipping,iu.user_picture " +
            "FROM order_goods_appraise t " +
            "LEFT JOIN goods g on t.goods_id = g.goods_id " +
            "LEFT JOIN infs_user iu on t.user_id = iu.user_id " +
            "where " +
            " t.goods_id = #{goodsId} " +
            " and t.oga_goods < #{ogaGoods} ")
    List<Map<String,Object>> queryNetiveComments(Pagination page,@Param("goodsId")Integer goodsId,@Param("ogaGoods")Integer ogaGoods);


    /**
     *
     * 查询中评
     * @param page
     * @param goodsId
     * @param ogaGoods
     * @return
     */
    @Select("SELECT t.goods_id,t.oga_text,iu.user_name,t.oga_service,t.oga_goods,t.oga_shipping,iu.user_picture " +
            "FROM order_goods_appraise t " +
            "LEFT JOIN goods g on t.goods_id = g.goods_id " +
            "LEFT JOIN infs_user iu on t.user_id = iu.user_id " +
            "where " +
            " t.goods_id = #{goodsId} " +
            " and t.oga_goods  = #{ogaGoods} ")
    List<Map<String,Object>> queryMidComments(Pagination page,@Param("goodsId")Integer goodsId,@Param("ogaGoods")Integer ogaGoods);

    /**
     * 获取微信小程序的顾客评价
     * @param goodsId
     * @return
     */
    @Select("select t1.oga_text,date_format(t1.create_time,'%Y-%m-%d') as create_time,t2.nick_name,t2.user_picture from order_goods_appraise t1 " +
            "left join infs_user t2 on t1.user_id = t2.user_id " +
            "where t1.goods_id=#{goodsId}")
    List<Map<String,Object>> queryCustomerAppraise(@Param("goodsId") Integer goodsId);

    /**
     * 新增商品评价
     * @param appraiseMap
     * @return
     */
    @Insert("insert into order_goods_appraise (order_id,goods_id,user_id,oga_text,oga_shipping," +
            "oga_service,oga_goods,create_time) values(#{appraiseMap.order_id},#{appraiseMap.goods_id}," +
            "#{appraiseMap.user_id},#{appraiseMap.oga_text},#{appraiseMap.oga_shipping},#{appraiseMap.oga_service},#{appraiseMap.oga_goods},now())")
    int addGoodsAppraise(@Param("appraiseMap")Map appraiseMap);

    /**
     * 获取相似推荐的商品
     * @param page
     * @param goodsId
     * @return
     */
    @Select("SELECT a.goods_id,a.goods_img from goods a where cat_id in (select b.cat_id from goods b where b.goods_id =#{goodsId}) and a.goods_id!=#{goodsId} and a.is_delete = 0")
    List<Map<String,Object>> queryRecommend(Pagination page,@Param("goodsId") Integer goodsId);

    /**
     * 获取商品的产品参数
     * @param goodsId
     * @return
     */
    @Select("select a.attr_name,ga.attr_value from goods_attr ga " +
            "left outer join attribute a on a.attr_id=ga.attr_id " +
            "left outer join goods_type gt  on gt.cat_id=a.cat_id " +
            "where ga.goods_id=#{goodsId} and gt.attr_group='pro_param'")
    List<Map<String,Object>> queryGoodsAttr(@Param("goodsId") Integer goodsId);

    /**
     * 删除具体商品属性
     * @param goodsId
     * @return
     */
    @Delete("delete from goods_attr where goods_id=#{goodsId}")
    int deleteGoodsAttr(@Param("goodsId")Integer goodsId);


    /**
     * 添加商品具体的属性
     * @param goodsMap
     * @return
     */
    @Insert("<script>insert into goods_attr(goods_id,attr_id,attr_value,color_value,user_id) values" +
            "   (#{goodsMap.goods_id},#{goodsMap.attr_id},#{goodsMap.attr_value},#{goodsMap.color_value},#{goodsMap.user_id})" +
            "</script>")
    int addGoodsAttr(@Param("goodsMap")Map<String,Object>goodsMap);

    /**
     * 步骤一保存
     * @author xxf
     * @date 2018/2/22
     * */
    @Update("update goods " +
            "set " +
            "cat_id = #{cat_id} " +
            "where goods_id = #{goods_id}")
    int modGoodsCat(@Param("goods_id")Integer goods_id,@Param("cat_id") Integer cat_id);

    /**
     * 步骤二保存
     * @author xxf
     * @date 2018/2/22
     * */
    @Update("update goods " +
            "set " +
            "goods_name = #{goodsMap.goods_name}," +
            "brand_id = #{goodsMap.brand_id}," +
            "goods_number = #{goodsMap.goods_number}," +
            "goods_weight = #{goodsMap.goods_weight}," +
            "market_price = #{goodsMap.market_price}," +
            "cost_price = #{goodsMap.cost_price}," +
            "supply_price = #{goodsMap.supply_price}," +
            "shop_price = #{goodsMap.shop_price}," +
            "warn_number = #{goodsMap.warn_number}," +
            "keywords = #{goodsMap.keywords}," +
            "goods_brief = #{goodsMap.goods_brief}," +
            "goods_desc = #{goodsMap.goods_desc}," +
            "goods_img = #{goodsMap.goods_img}," +
            "is_real = #{goodsMap.is_real}," +
            "is_on_sale = #{goodsMap.is_on_sale}," +
            "is_alone_sale = #{goodsMap.is_alone_sale}," +
            "sort_order = #{goodsMap.sort_order} " +
            "where goods_id = #{goodsMap.goods_id}")
    int modGoodsGI(@Param("goodsMap") Map goodsMap);

    /**
     * 步骤三保存
     * @author xxf
     * @date 2018/2/22
     * */
    @Update("update goods " +
            "set " +
            "is_best = #{goodsMap.is_best}," +
            "is_new = #{goodsMap.is_new}," +
            "is_hot = #{goodsMap.is_hot}," +
            "is_promote = #{goodsMap.is_promote}," +
            "promote_price = #{goodsMap.promote_price}," +
            "promote_start_date = #{goodsMap.promote_start_date}," +
            "promote_end_date = #{goodsMap.promote_end_date}," +
            "is_xiangou = #{goodsMap.is_xiangou}," +
            "xiangou_start_date = #{goodsMap.xiangou_start_date}," +
            "xiangou_end_date = #{goodsMap.xiangou_end_date}," +
            "xiangou_num = #{goodsMap.xiangou_num} " +
            "where goods_id = #{goodsMap.goods_id}")
    int modGoodSI(@Param("goodsMap") Map goodsMap);

    /**
     * 查询开启状态的店铺
     * @return
     */
    @Select("select t2.id, t1.shop_name from seller_shopinfo t1 " +
            "LEFT JOIN  infu_admin_seller_rel t2 on t2.id = t1.id " +
            "where t2.user_id=#{shopMap.user_id}")
    List<Map<String, Object>> queryShopList(@Param("shopMap") Map<String, Object> shopMap);
}
